/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package staffTests;

import java.util.Calendar;
import model.Constants;
import model.personInfo.Contacts;
import model.personInfo.Name;
import model.personInfo.Origin;
import model.staff.Person;
import model.staff.Student;
import model.universityUnits.DepartmentInterface;
import model.universityUnits.GroupInterface;
import org.junit.*;
import static org.junit.Assert.*;

/**
 *
 * @author Slayer
 */
public class StudentTest {
    private Student student;
    
    private final Name name;
    private final Origin origin;
    private final Contacts contacts;
    
    public StudentTest() {
        name = new Name("Dmitri", "Paziy");
        origin = new Origin(Calendar.getInstance().getTime(), "Kriviy Rig");
        contacts = new Contacts("12345", "Kyiv");
    }
    
    @Before
    public void setUp() {
        student = new Student(name, origin, contacts);
    }
    
    @After
    public void tearDown() {
    }
    
    @Test
    public void shouldReturnNoCourseWhenCourseNotSet() {
        //given
        int expected = 0;
        //then
        assertEquals(expected, student.getCourse());
    }
    
    @Test(expected=IllegalArgumentException.class)
    public void shouldThrowIllegalArgumentExceptionWhenSetNegativeCourse() {
        student.setCourse(-1);
    }
    
    @Test(expected=IllegalArgumentException.class)
    public void shouldThrowIllegalArgumentExceptionWhenSetIncorrectCourse() {
        student.setCourse(Constants.MAXIMUM_COURSE + 1);
    }
    
    @Test
    public void shouldReturnNullWhenGroupNotSet() {
        //given
        GroupInterface expected = null;
        //then
        assertEquals(expected, student.getGroup());
    }
    
    @Test(expected=IllegalArgumentException.class)
    public void shouldThrowIllegalArgumentExceptionWhenSetNullGroup() {
        student.setGroup(null);
    }
    
    @Test
    public void shouldChangeGroupWhenSet() {
        //given
        GroupInterface group = new GroupInterface() {

            @Override
            public DepartmentInterface getDepartment() {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            @Override
            public Student getHeadman() {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            @Override
            public String getName() {
                return "Dummy";
            }

            @Override
            public Student get(int index) {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            @Override
            public int size() {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            @Override
            public Object[] toArray() {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            @Override
            public int capacity() {
                throw new UnsupportedOperationException("Not supported yet.");
            }
        };
        String expected = group.getName();
        //when
        student.setGroup(group);
        //then
        assertEquals(expected, student.getGroup().getName());
    }
    
    @Test
    public void testEquals() {
        //given
        Student studentClone = new Student(name, origin, contacts);
        //then
        assertEquals(studentClone, student);
    }
    
    @Test
    public void testToString() {
        //given
        String expected = "Student info: "
                + Constants.LINE_SEPARATOR
                + student.getName().toString()
                + student.getOrigin().toString()
                + student.getContacts().toString()
                + "Course: 1"
                + Constants.LINE_SEPARATOR
                + "Group: none";
        //when
        student.setCourse(1);
        //then
        assertEquals(expected, student.toString());
    }
}
